package com.lagou.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.lagou.entity.UserCourseOrder;
import com.lagou.service.OrderService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("order")
public class OrderController {
    @Reference
    private OrderService orderService;

    @GetMapping("saveOrder")
    public String saveOrder(String orderNo, String userId, String courseId,
                            String activityCourseId, String sourceType) {
        orderService.saveOrder(orderNo, userId, courseId, activityCourseId, sourceType);

        return orderNo;
    }

    @GetMapping("updateOrder")
    public Integer updateOrder(String orderNo, Integer status) {
        return orderService.updateOrder(orderNo, status);
    }

    @GetMapping("deleteOrder/{orderNo}")
    public Integer deleteOrder(@PathVariable String orderNo) {
        return orderService.deleteOrder(orderNo);
    }

    @GetMapping("getOrdersByUserId/{userId}")
    public List<UserCourseOrder> getOrdersByUserId(@PathVariable String userId) {
        return orderService.getOrdersByUserId(userId);
    }
}
